<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.7
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ################














$myConfig = $DB->fetchAll('SELECT * FROM '.$CONFIG->dbprefix.'jfxlinker_config');
$accessGroups = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}iusers_groups");
$countries = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}iusers_countries ORDER BY title ASC");

$conf = array();
foreach($myConfig as $k=>$v){
    $conf[$v['k']] = $v['v'];
};

if(Antz_IntelliForm::submitted('config')){
    $newParams = array();

    foreach($_POST as $k=>$v){
        if(!array_key_exists($k, $conf)) continue;

        //$DB->debug(true);
        //$DB->showErrors(true);
        $DB->update($CONFIG->dbprefix.'jfxlinker_config', array('v'=>$v), "k = '{$k}'");
    };
    JFX::addSuccess($this->Lang('config_success'));
}

$myConfig = $DB->fetchAll('SELECT * FROM '.$CONFIG->dbprefix.'jfxlinker_config');
$accessGroups = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}iusers_groups");
$countries = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}iusers_countries ORDER BY title ASC");

$conf = array();
foreach($myConfig as $k=>$v){
    $conf[$v['k']] = $v['v'];
};



$form = new JFX_Form('config');
$form->setAction($actionUrls['config']);
$block = $form->add('full');
$fs = $block->add($this->Lang('config_settings'));


// add all the other fields
foreach($myConfig as $k=>$row){
    

    if($row['field_type']=='boolean'){
        $rad = $fs->addRadioGroup($row['k'], $row['title'], $row['v']);
        $rad->add('1', $this->Lang('yes'));
        $rad->add('0', $this->Lang('no'));
    }else if($row['field_type']=='page'){
    	global $gCms;
        $sel = $fs->addSelect($row['k'], $row['title'], $row['v']);
        JFX::addPagesToDropMenu($sel, '0', '1');
    }else{
        $inpt = $fs->addInput('text', $row['k'], $row['title'], $row['v']);
        $inpt->addAftertext('('.$row['field_type'].')');
        if($row['field_type']=='string') $inpt->addClass('extra-wide');
    }


};



$fs->addInput('submit', 'submitBtn', '&nbsp;', 'Update config');

$SMARTY->assign('configForm', $form->render());











echo $this->fetchTemplate('admin.config.tpl');
